package day16;

//本类是测试线程安全问题的演示demo
public class TestThread {
    public static void main(String[] args) {
        TicketThread t1 = new TicketThread();
        TicketThread t2 = new TicketThread();
        TicketThread t3 = new TicketThread();
        TicketThread t4 = new TicketThread();
        t1.start();
        t2.start();
        t3.start();
        t4.start();

    }
}
class TicketThread extends Thread {
    static int ticket = 10;

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(10);
            }catch (Exception e){
                e.printStackTrace();
            }

            System.out.println(getName() + "=" + ticket--);
            if (ticket <= 0) break;
        }
    }
}